package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 1 on 2018/6/3.
 */
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            //将信息使用doPost方法执行   对应jsp页面中的form表单中的method
        }

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String username = req.getParameter("username"); //得到jsp页面传过来的参数
        String password = req.getParameter("password");

            req.setAttribute("john", "欢迎用户" + username); //向request域中放置信息
            req.getRequestDispatcher("/welcome.jsp").forward(req, resp);//转发到欢迎页面
            resp.sendRedirect("default.jsp"); //重定向到
        }
    }

